package com.guan.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guan.commonutils.R;
import com.guan.eduservice.entity.EduCourse;
import com.guan.eduservice.entity.EduTeacher;
import com.guan.eduservice.service.EduCourseService;
import com.guan.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Date: 2023/4/21 14:18
 * @Author: 管奇安
 * @Description:
 */
@RestController
@RequestMapping("/eduservice/teacherfront/")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //分页查询讲师
    @PostMapping("getTeacherFront/{page}/{limit}")
    public R getTeacherFront(@PathVariable long page, @PathVariable long limit){
        Page<EduTeacher> teacherPage = new Page<>(page,limit);
        Map<String, Object> map = teacherService.getTeacherFrontList(teacherPage);

        return R.ok().data(map);
    }


    @GetMapping("getTeacherDetail/{teacherId}")
    public R getTeacherDetail(@PathVariable String teacherId){

        //查讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);

        //根据讲师id查询讲师课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);

        return R.ok().data("eduTeacher",eduTeacher).data("courseList",courseList);
    }

}
